<?php

namespace App\Admin\Controllers;

use App\Models\UserFeedback;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class FeedbacksController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '反馈';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserFeedback);

        $grid->column('id', __('Id'));
        $grid->column('user_id', __('用户'))->display(function(){
            return User::getMobileById($this->user_id);
        });
        $grid->column('bref', __('返回内容'));
        $grid->column('contact', __('联系方式'));
        $states = [
        	'on'  => ['value' => 1, 'text' => '已处理', 'color' => 'primary'],
        	'off' => ['value' => 0, 'text' => '未处理', 'color' => 'default'],
        ];
        $grid->column('status', __('状态'))->switch($states);
        $grid->column('created_at', __('反馈时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(UserFeedback::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('bref', __('Bref'));
        $show->field('contact', __('Contact'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new UserFeedback);

        $form->text('bref', __('反馈内容'))->readonly();
        $form->text('contact', __('联系方式'))->readonly();
        $states = [
        	'on'  => ['value' => 1, 'text' => '已处理', 'color' => 'primary'],
        	'off' => ['value' => 0, 'text' => '未处理', 'color' => 'default'],
        ];
        $form->switch('status', __('状态'))->states($states);
        return $form;
    }
}
